package com.crane.app.web.controller;


import com.crane.common.core.dto.MultiResponse;
import com.crane.common.core.utils.BaseContextHandler;
import com.crane.oss.app.service.AppUserService;
import com.crane.oss.school.bean.resp.StudentResp;
import com.crane.oss.school.bean.resp.TeacherResp;
import com.crane.oss.school.service.TeacherService;
import com.crane.oss.sports.XunFeiAppApiService;
import com.crane.oss.xunfei.req.QueryAppParentIndexReq;
import com.crane.oss.xunfei.req.QueryAppTeacherIndexReq;
import com.crane.oss.xunfei.resp.ApiListResponse;
import com.crane.oss.xunfei.resp.AppParentIndexResp;
import com.crane.oss.xunfei.resp.AppTeacherIndexResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

@Api(value = "AppIndexController", tags = {"首页"})
@RestController
@RequestMapping("/app/index")
public class AppIndexController {

    @Resource
    AppUserService appUserService;

    @Resource
    TeacherService teacherService;

    @Resource
    XunFeiAppApiService xunFeiAppApiService;


    @ApiOperation(value = "家长-首页列表", notes = "家长-首页列表")
    @PostMapping("/parentList")
    public MultiResponse<AppParentIndexResp> parentList () {
        Long userId=BaseContextHandler.getUserId();
        StudentResp studentResp=appUserService.getDefaultStudent(userId);
        if(null == studentResp){
            return MultiResponse.buildFailure("未绑定学生");
        }
        QueryAppParentIndexReq req=new QueryAppParentIndexReq();
        req.setStudentId(studentResp.getStudentId().toString());
        ApiListResponse<AppParentIndexResp> response=xunFeiAppApiService.getParentIndex(req,studentResp.getPartyId().toString(),null,userId.toString());
        if(null!=response && response.getMsg().equals("success")){
            return MultiResponse.ofWithoutTotal(response.getData());

        }
        return MultiResponse.ofWithoutTotal(new ArrayList<>());
    }


    @ApiOperation(value = "老师-首页列表", notes = "老师-首页列表")
    @PostMapping("/teacherList")
    public MultiResponse<AppTeacherIndexResp> teacherList () {
        Long userId=BaseContextHandler.getUserId();
        TeacherResp teacherResp=teacherService.queryTeacherByAppUserId(userId);
        QueryAppTeacherIndexReq req=new QueryAppTeacherIndexReq();
        req.setTeacherId(teacherResp.getTeacherId().toString());
        ApiListResponse<AppTeacherIndexResp> response=xunFeiAppApiService.getTeacherIndex(req,teacherResp.getPartyId().toString(), null,userId.toString());
        if(null!=response && response.getMsg().equals("success")){
            return MultiResponse.ofWithoutTotal(response.getData());

        }
        return MultiResponse.ofWithoutTotal(new ArrayList<>());
    }

}
